<?php
/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

print "<br>";

function quote_smart($value, $handle) {

    if (get_magic_quotes_gpc()) {
        $value = stripslashes($value);
    }

    if (!is_numeric($value)) {
        $value = "'" . mysql_real_escape_string($value, $handle) . "'";
    }
    return $value;
}

if ($_SERVER['REQUEST_METHOD'] == 'POST') {
    $uname = $_POST['username'];
    $level = $_POST['level'];

    $uname = htmlspecialchars($uname);

    $user_name = "root";
    $pass_word = "haddons";
    $database = "PPI";
    $server = "127.0.0.1";

    $db_handle = mysql_connect($server, $user_name, $pass_word);
    $db_found = mysql_select_db($database, $db_handle);

    if ($db_found) {
        $q_uname = quote_smart($uname, $db_handle);
        $SQL = "UPDATE `PPI`.`users` SET `authorised` = '$level' WHERE `login_ID` = $q_uname";
        print $SQL . "<br>";
        $result = mysql_query($SQL);

        if ($result == NULL) {
            print "null<br>";
        } else {
            print "not null<br>";
        }
    }
} else {
    print "nothing posted<br>";
}
?>
<!DOCTYPE html>
<html>
    <head>
        <title></title>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <link rel="stylesheet" href="./css/main.css" type="text/css">
    </head>
    <body>
        <?PHP
        include 'i_authForm.html';
        include 'i_foot.html';
        ?>